package com.lineage.data.item_etcitem.mp;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.skill.L1BuffUtil;
import com.lineage.server.serverpackets.S_PacketBox;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.ServerBasePacket;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UserMprBlue extends ItemExecutor {
  private static final Log _log = LogFactory.getLog(UserMprBlue.class);
  
  private int _time;
  
  private int _gfxid;
  
  public static ItemExecutor get() {
    return new UserMprBlue();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    try {
      if (item == null)
        return; 
      if (pc == null)
        return; 
      if (L1BuffUtil.stopPotion(pc)) {
        pc.getInventory().removeItem(item, 1L);
        if (pc.hasSkillEffect(1002))
          pc.killSkillEffectTimer(1002); 
        L1BuffUtil.cancelAbsoluteBarrier(pc);
        if (this._gfxid > 0)
          pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), this._gfxid)); 
        pc.sendPackets((ServerBasePacket)new S_PacketBox(34, this._time));
        pc.setSkillEffect(1002, this._time * 1000);
        pc.sendPackets((ServerBasePacket)new S_ServerMessage(1007));
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._time = Integer.parseInt(set[1]);
      if (this._time <= 0) {
        this._time = 600;
        _log.error("UserMpr 设置错误:时效小于等于0! 使用预设600");
      } 
    } catch (Exception exception) {}
    try {
      this._gfxid = Integer.parseInt(set[2]);
    } catch (Exception exception) {}
  }
}
